/**
 * 
 */
package com.example.rabbitmqTest;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;  
/**
 * @author yanglei
 * 2018年1月15日
 */
@Controller  
@RequestMapping("/receipt")
public class ReceiptController {  
  
    private static final Logger log= LoggerFactory.getLogger(ReceiptController.class);  
  
  
    @Autowired  
    private ReceiptService receiptService;  
  
    /** 
     * 收客户钱，录收款单 
     * @param addDto 
     * @param bindingResult 
     * @return 
     * @throws Exception 
     * 
     * receiptNo=123131receiptNo1&receiptPrice=1231.123&receiptDateStr=2017-12-12&customerId=1231
     */  
    @SuppressWarnings("rawtypes")
	@RequestMapping(value = "/add",method = RequestMethod.GET)  
    @ResponseBody  
    public BaseResponse add(@Valid  ReceiptAddDto addDto, BindingResult bindingResult) throws Exception{  
        if (bindingResult.hasErrors()){  
           // return new BaseResponse(new Status());  
        }  
        //其余业务上的校验逻辑:比如日期格式、客户id对应的客户是否存在、客户id对应的客户是否可以收款 ....  
  
       BaseResponse response=new BaseResponse(new Status());  
        try {  
            receiptService.insert(addDto);  
        }catch (Exception e){  
            log.error("录入收款单发生异常： {} ",addDto,e.fillInStackTrace());  
            response=new BaseResponse(new Status());  
        }  
        return response;  
    }  
}  